

#ifndef LCD1602_H__DEF
#define LCD1602_H__DEF

#include "reg51.h"
#include "intrins.h"

#define NULL ((void *)0) 

#define FALSE 0
#define TRUE  1
#define DB    P2
#define bool  bit

sbit RS = P1^0;
sbit RW = P1^1;
sbit EN = P1^2;

extern void LCDInit(void);
extern void LCDDisplyChar(unsigned char u8PosX, unsigned char u8PosY, unsigned char u8Char);
extern void LCDDisplayStr(unsigned char u8PosX, unsigned char u8PosY, const char *pStr, unsigned char u8StrLen);
extern bool DIYChar(unsigned char u8Addr, const unsigned char *pu8Char);
extern void LCDClear(void);

#define CMD_SCREEN_CLEAR		0x01

#define CMD_CURSOR_RETURN	    0x02

#define CMD_INPUT_MODE          0x04 
#define	CMD_CURSOR_SHIFT_R      0x02
#define CMD_CURSOR_SHIFT_L      0x00
#define CMD_CHAR_SHIFT_ENABLE   0x01
#define CMD_CHAR_SHIFT_DISABLE  0x00

#define CMD_DISPLAY_MODE        0x08
#define CMD_DISPLAY_ON          0x04
#define CMD_DISPLAY_OFF         0x00
#define CMD_CURSOR_ON           0x02
#define CMD_CURSOR_OFF          0x00
#define CDM_CURSOR_FLASH        0x01
#define CMD_CURSOR_UNFLASH      0x00

#define CMD_MOVE_MODE           0x10
#define CMD_CHAR_MOVE           0x08
#define CMD_CURSOR_MOVE         0x00
#define CMD_SHIFT_R             0x04
#define CMD_SHIFT_L             0x00

#define CMD_CONFIG_MODE         0x20
#define CMD_CONFIG_8_BUS        0x10
#define CMD_CONFIG_4_BUS        0x00
#define CMD_CONFIG_2_LINE       0x08
#define CMD_CONFIG_1_LINE       0x00
#define CMD_CONFIG_5X10_SIZE    0x04
#define CMD_CONFIG_5X7_SIZE     0x00


#define LCDClear()				LCDWriteCmd(CMD_SCREEN_CLEAR)
#define LCDCursorReturn()		LCDWriteCmd(CMD_CURSOR_RETURN)
#define LCDSetCursorLoc(x, y)	LCDWriteCmd(0x80 + (y * 0x40) + x)

#endif